package com.lemon.smartsafety.ui.adapter.fire;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.result.fire.PersonalSResult;
import com.lemon.smartsafety.ui.activity.fire.FirefightingUtil;
import com.lemon.smartsafety.utils.CommonUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/9/8 9:45
 * 修改人：Fargo
 * 修改时间：2016/9/8 9:45
 * 修改备注：
 */
public class FireSituationPersonalAdapter extends BaseAdapter {

    /**
     * TAG
     */
    private final String TAG = "FireSituationPersonalAdapter";

    /**
     * 选择项
     */
    private int m_nSelectItem = -1;

    /**
     * 数据列表
     */
    private List<PersonalSResult> mList;


    /**
     * 布局泵
     */
    private LayoutInflater m_layInflater = null;

    private Context mContext;

    //是否显示右箭头
    private boolean isShowArrowRight = true;


    public boolean isShowArrowRight() {
        return isShowArrowRight;
    }

    public void setShowArrowRight(boolean showArrowRight) {
        isShowArrowRight = showArrowRight;
    }


    /**
     * 设置选择项
     *
     * @param n
     */
    public void setSelectItem(final int n) {
        m_nSelectItem = n;
    }

    /**
     * 设置数据列表
     */
    public void setList(ArrayList<PersonalSResult> list) {
        this.mList = list;
    }

    /**
     * 构造函数
     *
     * @param context
     */
    public FireSituationPersonalAdapter(Context context, List<PersonalSResult> list) {
        try {
            this.mContext = context;

            this.mList = list;

            // 布局泵
            m_layInflater = LayoutInflater.from(context);

        } catch (Exception e) {
        }
    }

    @Override
    public int getCount() {
        try {
            if (mList != null)
                return mList.size();
        } catch (Exception e) {
        }

        return 0;
    }

    @Override
    public Object getItem(int position) {
        try {
            if (mList != null)
                return mList.get(position);
        } catch (Exception e) {
        }

        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings({"deprecation"})
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        try {

            final ViewHolder holder;
            if (convertView == null) {
                convertView = m_layInflater.inflate(R.layout.item_personal_situation, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }


            try {
                if (!CommonUtil.strIsEmpty(mList.get(position).getRemark())) {
                    holder.txtSub.setVisibility(View.VISIBLE);
                    holder.txtSub.setText("备注:  " + mList.get(position).getRemark());
                } else {
                    holder.txtSub.setVisibility(View.GONE);
                }

                if (!CommonUtil.strIsEmpty(mList.get(position).getPosition())) {
                    holder.txtDirection.setVisibility(View.VISIBLE);
                    holder.txtDirection.setText("方位信息:  " + mList.get(position).getPosition());
                } else {
                    holder.txtDirection.setVisibility(View.GONE);
                }


                holder.txtTitle.setText(mList.get(position).getObjectTitle());
                holder.txtContent1.setText("  "+mList.get(position).getCheckValidity() + mList.get(position).getUnitName());
                holder.txtContent2.setText("  "+mList.get(position).getLastCheckUserName() + "  " + mList.get(position).getLastCheckDate());

                holder.imageCircle.setBackgroundResource(FirefightingUtil.getScoreImgCircleColor(mList.get(position).getStatus()));

            } catch (Exception e) {
                e.printStackTrace();
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.txt_title)
        TextView txtTitle;
        @Bind(R.id.txt_sub)
        TextView txtSub;
        @Bind(R.id.image_circle)
        ImageView imageCircle;
        @Bind(R.id.txt_direction)
        TextView txtDirection;
        @Bind(R.id.txt_content1)
        TextView txtContent1;
        @Bind(R.id.txt_content2)
        TextView txtContent2;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


    /**
     * 项支持器类
     */


}